import os
import wx

class LoginDialog(wx.Dialog):
  def __init__(self, parent, icopath, title, userinfo):
    self.userinfo = ['', '']
    #self.userinfo[0] = ""
    #self.userinfo[1] = ""
    self.userinfo = userinfo
    
    wx.Dialog.__init__(self, parent, title=title,style=wx.DEFAULT_DIALOG_STYLE,size=(400, 300), pos=wx.DefaultPosition,)
        
    self.SetIcon(wx.Icon(icopath,wx.BITMAP_TYPE_ICO))        
    
    sizer = wx.BoxSizer(wx.VERTICAL)

    label = wx.StaticText(self, -1, "Input your gmail account and password to login")    
    sizer.Add(label, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
    
    box = wx.BoxSizer(wx.HORIZONTAL)
    username = wx.StaticText(self, -1, "account:")
    username.SetHelpText("This is the help text for the label")
    #box.Add(username, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
    box.Add(username, 0, wx.ALIGN_RIGHT|wx.ALL, 5)
    
    self.username_text = wx.TextCtrl(self, -1, "", size=(50,-1))
    box.Add(self.username_text, 1, wx.ALIGN_CENTRE|wx.ALL, 5)

    sizer.Add(box, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)

    box = wx.BoxSizer(wx.HORIZONTAL)

    password = wx.StaticText(self, -1, "password:")
    box.Add(password, 0, wx.ALIGN_RIGHT|wx.ALL, 5)

    self.password_text = wx.TextCtrl(self, -1, "", size=(50,-1), style = wx.TE_PASSWORD)
    box.Add(self.password_text, 1, wx.ALIGN_CENTRE|wx.ALL, 5)

    sizer.Add(box, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)

    line = wx.StaticLine(self, -1, size=(20,-1), style=wx.LI_HORIZONTAL)
    sizer.Add(line, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.RIGHT|wx.TOP, 5)    
    
    btnsizer = wx.StdDialogButtonSizer()
        
    ok_btn = wx.Button(self, wx.ID_OK)
    ok_btn.SetDefault()
    btnsizer.AddButton(ok_btn)

    btn = wx.Button(self, wx.ID_CANCEL)
    btnsizer.AddButton(btn)
    btnsizer.Realize()

    sizer.Add(btnsizer, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)

    self.SetSizer(sizer)
    sizer.Fit(self)

    self.Bind(wx.EVT_BUTTON, self.OnButton, ok_btn)
    
    self.CenterOnScreen()
    self.ShowModal()
    
  def OnButton(self, event):
    account = self.username_text.GetValue()
    password = self.password_text.GetValue()
    
    if len(account) == 0 or len(password) == 0:
      info = wx.AboutDialogInfo()
      info.Name = "Input error"
      info.Description = 'account or password empty'
      wx.AboutBox(info)
    else:
      self.userinfo[0] = account
      self.userinfo[1] = password
      self.Destroy()
      
    